"""
	Developerd by Andrea Stagi <stagi.andrea@gmail.com>
	TwittLine - the client twitter on your terminal
	Copyright (C) 2010 Andrea Stagi

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from modules.graphic import twittcolor
from modules import twittutils
import os
import pickle

class settings:
	values=[0,0,0]

def setColors():

	getColors()

	if(os.name!="posix"):
		print "Only avaible in posix systems"
		return

	i=0

	print "";

	twittcolor.colorprintln("Twittline has these colors avaible:\n",0)
	
	for col in twittcolor.colors.v:
		i+=1
		print col + "[%d]" % (i) + twittcolor.colors.ENDC,

	print "\n"

	twittcolor.colorprint("Select the first color: ",0),
	first = raw_input(" ")
	twittcolor.colorprint("Select the second color: ",1),
	second = raw_input("")
	twittcolor.colorprint("Select the third color for favorites: ",2),
	third = raw_input("")

	twittcolor.palette.col[0]=twittcolor.colors.v[twittutils.stringToInt(first)-1]
	twittcolor.palette.col[1]=twittcolor.colors.v[twittutils.stringToInt(second)-1]
	twittcolor.palette.col[2]=twittcolor.colors.v[twittutils.stringToInt(third)-1]

	settings.values[0]=int(first)-1
	settings.values[1]=int(second)-1
	settings.values[2]=int(third)-1

	if(os.name=="posix"):
		f = open(os.path.dirname(__file__) + '/_res/settings.twl', 'wb')
	else:
		f = open('\res\settings.twl', 'wb')

	pickle.dump(settings.values, f)

	print "";

	twittcolor.colorprintln("******************************************************",2)
	twittcolor.colorprintln("\ \  \ \ Here's the new colors for Twittline / /  / / ",0)
	twittcolor.colorprintln(" | |  | |        !Hey I'm the second!       | |  | |  ",1)
	twittcolor.colorprintln("/ /  / /    Launch your fashion Twittline!   \ \  \ \ ",0)
	twittcolor.colorprintln("******************************************************",2)

	print "";

	f.close()

def getColors():

	if(os.name=="posix"):
		f = open(os.path.dirname(__file__) + '/_res/settings.twl', 'rb')
	else:
		f = open("res\\settings.twl", 'rb')
	
	settings.values = pickle.load(f)

	twittcolor.palette.col[0]=twittcolor.colors.v[settings.values[0]]
	twittcolor.palette.col[1]=twittcolor.colors.v[settings.values[1]]
	twittcolor.palette.col[2]=twittcolor.colors.v[settings.values[2]]

	f.close()

def getHelp():

	if(os.name=="posix"):
		f = open(os.path.dirname(__file__) + '/_res/help.twl', 'r')
	else:
		f = open('\res\help.twl', 'r')

	twittcolor.colorprint(f.read(),0)

	f.close()

def getLicence():

	if(os.name=="posix"):
		f = open(os.path.dirname(__file__) + '/_res/about.twl', 'r')
	else:
		f = open('\res\about.twl', 'r')

	twittcolor.colorprint(f.read(),0)

	f.close()

